<template>
  <a-upload
    v-model:file-list="fileList"
    name="file"
    :multiple="true"
    action="http://up-z0.qiniup.com"
    :headers="headers"
    :beforeUpload="beforeUpload"
    @change="handleChange"
  >
    <a-button>
      <upload-outlined></upload-outlined>
      点击上传文件
    </a-button>
  </a-upload>
</template>
<script lang="ts">
import { message } from 'ant-design-vue';
import { defineComponent, ref } from 'vue';

interface FileItem {
  uid: string;
  name?: string;
  status?: string;
  response?: string;
  url?: string;
}

interface FileInfo {
  file: FileItem;
  fileList: FileItem[];
}

export default defineComponent({
    components: {

    },
    props:{
        value:{
            require:true,
            default:()=>{
                return []
            }
        },
    },
    setup(props,{emit}) {
        const handleChange = (info: FileInfo) => {
            if (info.file.status !== 'uploading') {
                console.log(info.file, info.fileList);
            }
            if (info.file.status === 'done') {
                message.success(`${info.file.name} file uploaded successfully`);
            } else if (info.file.status === 'error') {
                message.error(`${info.file.name} file upload failed.`);
            }
        };
        let token:string=''
        const beforeUpload=(file: FileItem)=>{  //上传前获取token
            
        }

        const fileList = ref([]);
        return {
            fileList,
            headers: {
                token,
            },
            handleChange,
            beforeUpload
        };
    },
});
</script>

